home *** CD-ROM | disk | FTP | other *** search
/ The Utilities Experience / The Utilities Experience - Volume 1.iso / software / icons+tools / picticon / source / shovecolors.e < prev    next >
Text File  |  1995-12-22  |  8KB  |  324 lines

  1. MODULE 'exec/memory',
  2.              'intuition/intuition','intuition/screens','intuition/gadgetclass',
  3.              'intuition/screens',
  4.              'graphics/rastport','graphics/gfx','graphics/text',
  5.              'graphics/view',
  6.              'libraries/iffparse','iffparse',
  7.              'dos/dos','dos/dosextens','dos/dosasl','exec/tasks',
  8.              'dos/notify','exec/ports'
  9.  
  10.     OBJECT bitmapheader
  11.         w:INT;h:INT;x:INT;y:INT
  12.         depth:CHAR;masking:CHAR
  13.         compression:CHAR;pad1:CHAR;transparentcolor:INT
  14.         xaspect:CHAR;yaspect:CHAR;pagewidth:INT;pageheight:INT
  15.     ENDOBJECT
  16.     DEF source[250]:STRING
  17.     DEF argarray[11]:LIST
  18.     DEF    iff=NIL:PTR TO iffhandle
  19.     DEF    ierror
  20.     DEF tryagain=0
  21.     DEF sp=NIL:PTR TO storedproperty
  22.     DEF body
  23.     DEF ditz,dang,dumb
  24. ->    DEF vp=NIL:PTR TO viewport
  25.     DEF cm
  26.     DEF depth,scratch
  27.     DEF rdarg
  28.     DEF viewport=NIL:PTR TO viewport
  29.     DEF scr=NIL:PTR TO screen,oldscr
  30.     DEF bitmap=NIL:PTR TO bitmap
  31.     DEF quiet=FALSE
  32.     DEF lock[260]:LIST
  33.     DEF lockmode=0 /* 0 means don't lock unless in palette*/
  34.     DEF force=0    /* 0 means don't override already locked pens! */
  35.  
  36.     DEF sw,sh,sb:PTR TO bitmap,sli,sf,svp,sbh,srpf,srp:PTR TO rastport,sbd
  37.     DEF osw,osh,osb:PTR TO bitmap,osli,osf,osvp,osbh,osrpf,osrp:PTR TO rastport,osbd
  38.  
  39.     DEF fnotify=0:PTR TO notifyrequest
  40.     DEF fport=0:PTR TO mp,sig
  41.     DEF fmsg=0:PTR TO notifymessage
  42.  
  43.     DEF snotify=0:PTR TO notifyrequest
  44.  
  45.     DEF pnotify=0:PTR TO notifyrequest
  46.  
  47.     DEF notify=FALSE,notifyloop=FALSE
  48.  
  49.     DEF wbverlauf=FALSE,wbverlauftask=0
  50.     DEF tries
  51.  
  52. PROC main() HANDLE
  53.     IF KickVersion(39)=NIL
  54.         WriteF('\nGet OS3.x (maybe a nice A1200?)\n')
  55.         CleanUp(21)
  56.     ENDIF
  57.     IF (wbmessage)
  58.         WriteF('\nCannot be run from WorkBench.\n\n(Press RETURN to close this window.)\n')
  59.         CleanUp(21)
  60.     ENDIF
  61.     NEW fnotify,snotify,pnotify
  62.  
  63.     iffparsebase:=OpenLibrary('iffparse.library',39)
  64.  
  65.     rdarg:=ReadArgs('FILE/A,Q=QUIET/S,F=FORCE/S,LA=LOCKALL/S,N=NOTIFY/S,WBV=SIGNALWBVERLAUF/S',argarray,0)
  66.     IF rdarg>0
  67.         IF argarray[0]<>NIL
  68.             StrCopy(source,argarray[0],ALL)
  69.         ENDIF
  70.         IF argarray[1]<>NIL
  71.             quiet:=TRUE
  72.         ENDIF
  73.         IF argarray[2]<>NIL
  74.             force:=TRUE
  75.         ENDIF
  76.         IF argarray[3]<>NIL
  77.             lockmode:=TRUE
  78.         ENDIF
  79.         IF argarray[4]<>NIL
  80.             notify:=TRUE
  81.         ENDIF
  82.         IF argarray[5]<>NIL
  83.             wbverlauf:=TRUE
  84.         ENDIF
  85.         FreeArgs(rdarg)
  86.     ELSE
  87.         Raise(1)
  88.     ENDIF
  89.     notifyloop:=TRUE
  90.     WHILE (notifyloop=TRUE)
  91.         IF (scr := LockPubScreen({work})) = NIL
  92.             Raise(1)
  93.         ELSE
  94.             bitmap:=scr.bitmap
  95.             viewport:=scr.viewport
  96.             depth:=bitmap.depth
  97.             cm:=viewport.colormap
  98.         ENDIF
  99.         iff:=AllocIFF()
  100.         iff.stream:=Open(source,MODE_OLDFILE)
  101.         IF (iff.stream)
  102.             InitIFFasDOS(iff)
  103.         ELSE
  104.             Raise(1)
  105.         ENDIF
  106.         ierror:=OpenIFF(iff,IFFF_READ)
  107.         ierror:=PropChunk(iff,"ILBM","LOCK")
  108.         ierror:=PropChunk(iff,"ILBM","CMAP")
  109.         ierror:=StopOnExit(iff,"ILBM","FORM")
  110.         ierror:=ParseIFF(iff,IFFPARSE_SCAN)
  111.  
  112.         IF(sp:=FindProp(iff,"ILBM","LOCK"))
  113.             body:=sp.data
  114.             FOR scratch:=0 TO (sp.size-1)
  115.                 ditz:=Char(body++)
  116.                 IF lockmode=0
  117.                     lockpen(scratch,ditz)
  118.                 ELSE
  119.                     lockpen(scratch,1)
  120.                 ENDIF
  121.             ENDFOR
  122.         ENDIF
  123.         IF(sp:=FindProp(iff,"ILBM","CMAP"))
  124.             body:=sp.data
  125.             FOR scratch:=0 TO (sp.size/3)-1
  126.                 ditz:=Char(body++)
  127.                 dang:=Char(body++)
  128.                 dumb:=Char(body++)
  129.                 IF (scratch<(Shl(1,depth)))
  130.                     IF lock[scratch]=FALSE
  131.                         setrgb32(viewport,scratch,ditz,dang,dumb)
  132.                     ENDIF
  133.                     IF force
  134.                         setrgb32(viewport,scratch,ditz,dang,dumb)
  135.                     ENDIF
  136.                 ENDIF
  137.             ENDFOR
  138.         ELSE
  139.             Raise(1)
  140.         ENDIF
  141.         IF (notify=0)
  142.             notifyloop:=FALSE
  143.         ELSE
  144.             IF scr            ->        KLUDGE KLUDGE KLUDGE  (but aren't all screen-change detection routines?!??)
  145.                 osw:=scr.width
  146.                 osh:=scr.height
  147.                 osb:=scr.bitmap
  148.                 osbd:=osb.depth
  149.                 osli:=scr.layerinfo
  150.                 osf:=scr.font
  151.                 osvp:=scr.viewport
  152.                 osbh:=scr.barheight
  153.                 osrp:=scr.rastport
  154.                 osrpf:=osrp.font
  155.                 UnlockPubScreen(0,scr);oldscr:=scr;scr:=0
  156.                 IF (fport=0) THEN fport:=CreateMsgPort()
  157.                 IF (fport)
  158.                     fnotify.name:='env:sys/screenmode.prefs'
  159.                     fnotify.flags:=NRF_SEND_MESSAGE
  160.                     fnotify.port:=fport
  161.                     snotify.name:='env:sys/font.prefs'
  162.                     snotify.flags:=NRF_SEND_MESSAGE
  163.                     snotify.port:=fport
  164.                     pnotify.name:=source
  165.                     pnotify.flags:=NRF_SEND_MESSAGE
  166.                     pnotify.port:=fport
  167.                     IF ((StartNotify(fnotify)) AND (StartNotify(snotify)) AND (StartNotify(pnotify)))
  168.                         IF (tryagain=0) THEN sig:=Wait(SIGBREAKF_CTRL_C OR (Shl(1,fport.sigbit)))
  169.                         IF (sig AND SIGBREAKF_CTRL_C)
  170.                             notifyloop:=FALSE
  171.                         ENDIF
  172.                         IF (sig AND Shl(1,fport.sigbit))
  173.                             IF ((fmsg:=GetMsg(fport)) OR (tryagain<>0))
  174.                                 tryagain:=0
  175.                                 IF (fmsg) THEN ReplyMsg(fmsg)
  176.                                 tries:=0
  177.                                 Delay(60)    -> Wait a bit, then we begin to bang on intuition...
  178.                                 REPEAT
  179.                                     Forbid()
  180.                                     scr:=LockPubScreen({work})
  181.                                     IF (scr)
  182.                                         sw:=scr.width
  183.                                         sh:=scr.height
  184.                                         sb:=scr.bitmap
  185.                                         sbd:=sb.depth
  186.                                         sli:=scr.layerinfo
  187.                                         sf:=scr.font
  188.                                         svp:=scr.viewport
  189.                                         sbh:=scr.barheight
  190.                                         srp:=scr.rastport
  191.                                         srpf:=osrp.font
  192.                                         UnlockPubScreen(0,scr)
  193.                                         Permit()
  194.                                     ELSE
  195.                                         Permit()
  196.                                         Delay(30)
  197.                                     ENDIF
  198.                                     tries:=tries+1
  199.                                 UNTIL (((scr>0) AND (oldscr<>scr)) OR (tries>=16) OR (sw<>osw) OR (sh<>osh) OR (sb<>osb) OR (sli<>osli) OR (sf<>osf) OR (svp<>osvp) OR (sbh<>osbh) OR (srp<>osrp) OR (srpf<>osrpf) OR (sbd<>osbd))
  200.                                 IF (tries>=14) THEN tryagain:=TRUE
  201.                                 scr:=0
  202.                                 IF (wbverlauf)
  203.                                     wbverlauftask:=FindTask('WBVerlauf')
  204.                                     IF (wbverlauftask)
  205.                                         Signal(wbverlauftask,$FFFF0FFF)
  206.                                     ENDIF
  207.                                 ENDIF
  208.                             ENDIF
  209.                         ENDIF
  210.                         EndNotify(fnotify)
  211.                         EndNotify(snotify)
  212.                         EndNotify(pnotify)
  213.                     ENDIF
  214.                     IF CtrlC()
  215.                         notifyloop:=FALSE
  216.                     ENDIF
  217.                 ELSE
  218.                     notifyloop:=FALSE
  219.                 ENDIF
  220.             ENDIF
  221.         ENDIF        
  222.         IF CtrlC() THEN (notifyloop:=FALSE)
  223.     ENDWHILE
  224. EXCEPT DO
  225.     IF ((notify) AND (quiet=FALSE)) THEN WriteF('***BREAK\n')
  226.     IF (fport)
  227.         IF (fnotify) THEN EndNotify(fnotify)
  228.         IF (snotify) THEN EndNotify(snotify)
  229.         IF (pnotify) THEN EndNotify(pnotify)
  230.         DeleteMsgPort(fport)
  231.     ENDIF
  232.  
  233.     END fnotify,snotify,pnotify
  234.     IF scr THEN UnlockPubScreen(0,scr)
  235.     IF (iff)
  236.         CloseIFF(iff)
  237.         IF (iff.stream) THEN Close(iff.stream)
  238.         FreeIFF(iff)
  239.     ENDIF
  240.     IF iffparsebase THEN CloseLibrary(iffparsebase)
  241.     IF ((exception) AND (quiet=FALSE)) THEN WriteF('ShoveColors Failed.\n')
  242. ENDPROC
  243.  
  244. PROC getrgb32(cm,fc,nc,tab)
  245.     DEF ret
  246.     MOVE.L cm,A0
  247.     MOVE.L fc,D0
  248.     MOVE.L nc,D1
  249.     MOVE.L tab,A1
  250.     MOVE.L gfxbase,A6
  251.     JSR    -$384(A6)
  252.     MOVE.L D0,ret
  253. ENDPROC ret
  254.  
  255. PROC setrgb32(vp,pen,red,green,blue)
  256.     MOVE.L vp,A0
  257.   MOVE.L pen,D0
  258.   MOVE.L red,D1
  259.   SWAP   D1
  260.   LSL.L  #8,D1
  261.   MOVE.L green,D2
  262.   SWAP   D2
  263.   LSL.L  #8,D2
  264.   MOVE.L blue,D3
  265.   SWAP   D3
  266.   LSL.L  #8,D3
  267.   MOVE.L gfxbase,A6
  268.   JSR    -$354(A6)
  269. ENDPROC
  270.  
  271. PROC obtainpen(cm,n,r,g,b,f)
  272.     DEF ret
  273.     MOVE.L gfxbase,A6
  274.     MOVE.L n,D0
  275.   MOVE.L r,D1
  276.   SWAP   D1
  277.   LSL.L  #8,D1
  278.   MOVE.L g,D2
  279.   SWAP   D2
  280.   LSL.L  #8,D2
  281.   MOVE.L b,D3
  282.   SWAP   D3
  283.   LSL.L  #8,D3
  284.     MOVE.L cm,A0
  285.     MOVE.L f,D4
  286.     JSR    -$3BA(A6)
  287.     MOVE.L D0,ret
  288. ENDPROC ret
  289.  
  290. PROC releasepen(cm,n)
  291.     MOVE.L cm,A0
  292.     MOVE.L n,D0
  293.     MOVE.L gfxbase,A6
  294.     JSR    -$3B4(A6)
  295. ENDPROC
  296.  
  297. PROC lockpen(pn,mode)
  298.  
  299.     DEF cmtable,red,green,blue,dummy
  300.  
  301.     cmtable:=[0,0,0,0,0,0]:LONG
  302.     getrgb32(cm,pn,1,cmtable)
  303.     red:=Char(cmtable)
  304.     green:=Char(cmtable+4)
  305.     blue:=Char(cmtable+8)
  306.  
  307.     dummy:=obtainpen(cm,pn,red,green,blue,0)
  308.  
  309.     IF dummy<0
  310.         lock[pn]:=TRUE /* Pen was unavailable, so DON'T release/change! */
  311.     ELSE
  312.         IF (mode=0) /* Was able to lock, but it needs to be *free* */
  313.             releasepen(cm,pn)
  314.         ENDIF
  315.         lock[pn]:=FALSE
  316.     ENDIF
  317. ENDPROC
  318.  
  319. versionstring:
  320. CHAR '\0$VER: shovecolors 0.4 (27.3.95)\0'
  321.  
  322. work:
  323. CHAR 'Workbench\0\0'
  324.